package com.woodblockwithoutco.remotecontrollerexample;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;

import com.woodblockwithoutco.remotecontrollerexample.TransportControlView.ArtworkChangeListener;

public class TransportControlActivity extends Activity {

    private TransportControlView mTcv;
    private ViewManagerHost mHostView;
    
    private TransportControlView.ArtworkChangeListener mBackgroundChanger = new ArtworkChangeListener() {
        
        @Override
        public void onSetBackground(Bitmap bmp) {
            mHostView.setCustomBackground(bmp != null ? new BitmapDrawable(getResources(), bmp) : null);
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_transport_control);
        mHostView = (ViewManagerHost) findViewById(R.id.background_frame);
        mTcv = (TransportControlView) findViewById(R.id.transport_control_view);
    }
    
    @Override
    protected void onStart() {
        super.onStart();
        mTcv.start();
        mTcv.registerArtworkChangeListener(mBackgroundChanger);
    }
    
    @Override
    protected void onStop() {
        super.onStop();
        mTcv.stop();
        mTcv.removeArtworkChangeListener(mBackgroundChanger);
    }
}
